package scheduler

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntityManager"
	"go-fox-edge-persist/entityUpdater"
	"time"
)

type PersistManageScheduler struct {
}

// Scheduler 创建一个线程
func (e *PersistManageScheduler) Scheduler() {
	go e.scheduler()
}

// 线程函数
func (e *PersistManageScheduler) scheduler() {
	for true {
		time.Sleep(1 * time.Second)
		if !commEntityManager.EntityManager.Initialized {
			continue
		}

		// 同步映射数据
		entityUpdater.SyncEntity()

		// 删除设备历史记录
		DeviceHistoryAdapter.ClearHistoryEntity()

		// 删除操作记录
		OperateRecordAdapter.ClearOperateRecord()

		// 删除设备记录
		DeviceRecordAdapter.ClearDeviceRecord()

		// 删除时间序列记录
		DeviceSequenceAdapter.ClearDeviceSequenceRecord()

		// 删除设备数值记录
		DeviceValueRecordAdapter.ClearDeviceValueRecordEntity()
	}
}
